﻿''' <summary>
''' 
''' </summary>
''' <remarks></remarks>
Public Class GestBDDCacheModeVirtuel

    Public PageSize As Integer = 5000
    Public TotalCount As Long
    ''''public NameList.GetNamesDataTable CachedData = null;

    ''''NameListTableAdapters.GetNamesTableAdapter _adapter =
    ''''    new DataGridViewVirtualModePaging.NameListTableAdapters.GetNamesTableAdapter();

    Protected _connection As OleDb.OleDbConnection
    Protected _sqlStr As String

    Protected _lastRowIndex As Integer = -1
    Protected _cachedData As Dictionary(Of Integer, DataTable)

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New(ByVal connection As OleDb.OleDbConnection, ByVal strRequete As String)
        _connection = connection
        _sqlStr = strRequete
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New(ByVal pageSize As Integer)
        pageSize = pageSize
        LoadPage(0)
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub LoadPage(ByVal rowIndex As Integer)

        Dim da As New OleDb.OleDbDataAdapter
        Dim ds As New DataSet
        Dim numPage As Integer = CType((rowIndex / PageSize), Integer)
        Dim lastRowIndex As Integer = numPage * (PageSize + 1)

        If _cachedData Is Nothing Then _cachedData = New Dictionary(Of Integer, DataTable)

        If Not _cachedData.ContainsKey(numPage) Then
            'Exécution de la requête
            _cachedData.Add(numPage, New DataTable())
            da.Fill(numPage * PageSize, 0, _cachedData(numPage))
        End If

        'If (lastRowIndex = _lastRowIndex) Then Return
        '_lastRowIndex = lastRowIndex
        'If (CachedData Is Nothing) Then CachedData = New NameList.GetNamesDataTable()
        'CachedData.Rows.Clear()
        'Dim totalCount As Long = 0
        '_adapter.Fill(CachedData, _lastRowIndex, PageSize, totalCount)
        'totalCount = totalCount.Value
    End Sub
End Class
